package entertainmentguide.entity;

//import java.sql.Date;
import java.sql.Time;
import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.StringTokenizer;
//import java.util.StringTokenizer;
/**
 *
 * 
 */
public class Reservation {
    private int resId;
    private int userId;
    private int restId;
    private Date rDate;
    private Time rTime;
    private int status;

    public Reservation(int resId,int userId, int restId, Date rDate, Time rTime, int status) {
        this.resId = resId;
        this.userId = userId;
        this.restId = restId;
        this.rDate = rDate;
        this.rTime = rTime;
        this.status=status;
    }

    public Reservation() {
        this.resId=0; // το ID θα παραχθεί αυτόματα από την database
    }
    
    public void setResId(int userId) {
        this.resId = resId;
    }

    public int getResId() {
        return resId;
    }
    
    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getUserId() {
        return userId;
    }

    public void setRestId(int restId) {
        this.restId = restId;
    }

    public int getRestId() {
        return restId;
    }

    public void setRDate(Date rDate) {
        this.rDate = rDate;
    }

    public Date getRDate() {
        return rDate;
    }

    public void setRTime(Time rTime) {
        this.rTime = rTime;
    }

    public Time getRTime() {
        return rTime;
    }
    
    public void setStatus(int status) {
        this.status = status;
    }

    public int getStatus() {
        return status;
    }
    

    @Override
    public String toString(){
        return  "\n" + " | " + "ReservationID: " + getResId() + " | " +
                "UserID: " + getUserId() + " | " +
                "RestID: " + getRestId() + " | " +
                "Ημέρα: " + getRDate() + " | " +
                "Ώρα: " + getRTime() + " | ";
    }

    /**
     * Creates a Reservation object by parsing line.
     * The line must be in the following format:
     * RESERVATION: <userId> <restId> <rDate> <rTime>
     *
     * @param line
     * @return
     */
    public static Reservation parseReservation(String line) throws IllegalArgumentException, ParseException{
        StringTokenizer strTok = new StringTokenizer(line);
        String s1 = strTok.nextToken(); // Reservation:
        String s2 = strTok.nextToken(); // resId
        String s3 = strTok.nextToken(); // userId
        String s4 = strTok.nextToken(); // restId
        String s5 = strTok.nextToken(); // rDate
        String s6 = strTok.nextToken(); // rTime
        String s7 = strTok.nextToken(); // status
        strTok.nextToken("\""); //Skip the first toker with "
        
        int d2 = Integer.parseInt(s2);
        int d3 = Integer.parseInt(s3);
        int d4 = Integer.parseInt(s4);
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        DateFormat tf = new SimpleDateFormat("hh:mm:ss");
        Date d5 = (Date) df.parse(s5); 
        Time d6 = (Time) tf.parse(s6);
        int d7 = Integer.parseInt(s7);
        
        return new Reservation(d2,d3,d4,d5,d6,d7);
    }

}
